package com.starleague.battletech.unit.mech.jpa.appengine;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

import com.starleague.battletech.unit.BattletechUnitEngineType;
import com.starleague.battletech.unit.IWeight;
import com.starleague.battletech.unit.jpa.appengine.BattletechUnitEngineGae;
import com.starleague.battletech.unit.mech.IMechEngine;

@Entity(name = "MECH_ENGINE")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class MechEngineGae
        extends BattletechUnitEngineGae
        implements IMechEngine
{
    // Remember, AppEngine doesn't support FetchType.EAGER / Joins
    @OneToOne(mappedBy = "engine", fetch = FetchType.LAZY, optional = false)
    private MechGae mech;

    @OneToMany(mappedBy = "engine", cascade = CascadeType.ALL)
    private List<MechEngineCriticalSlotGae> criticalSlots;

    MechEngineGae(MechGae mech,
                  IWeight weight,
                  BattletechUnitEngineType engineType,
                  int engineRating)
    {
        super(weight, engineType, engineRating);
        this.mech = mech;
        this.criticalSlots = new ArrayList<>();
    }

    protected MechEngineGae()
    {
        //
    }

    @Override
    public MechGae getMech()
    {
        return this.mech;
    }

    @Override
    protected List<MechEngineCriticalSlotGae> getCriticalSlots()
    {
        return this.criticalSlots;
    }
}
